package com.central.apps.controller;

import com.alibaba.fastjson.JSONObject;
import com.central.apps.entity.MpxjBean;
import com.central.apps.service.ProjectChangeService;
import io.swagger.annotations.Api;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 项目任务变更接口类
 *
 * @author 李大超
 * @date 2023/4/26
 */
@RestController
@Api(tags = "项目计划接口类")
@RequestMapping("/projectChange")
@Slf4j
public class ProjectChangeController {

    @Autowired
    private ProjectChangeService projectChangeService;

    @SneakyThrows
    @GetMapping("/viewTask")
    public String viewTask(Integer proId, Integer pcId, Integer taskId) throws Exception {
        JSONObject json = new JSONObject();
        Map<String, Object> map = projectChangeService.viewTask(proId, pcId, taskId);

        if(map != null){
            json.put("data", map);
        }

        return json.toJSONString();
    }

    @GetMapping("/view")
    public String viewSchedulePlan(Integer proId, Integer pcId) throws Exception {
        JSONObject json = new JSONObject();
        json.put("code", "0");
        MpxjBean mpxjBean = projectChangeService.viewPlan(proId, pcId);

        if (mpxjBean != null) {
            json.put("mpxjBean", mpxjBean);
        }

        return json.toJSONString();
    }

    @PostMapping("/modify")
    public String modifySchedulePlan(@RequestBody MpxjBean mpxjBean, Integer proId, Integer pcId) throws Exception {
        JSONObject json = new JSONObject();
        json.put("code", "0");
        json.put("msg", "保存成功");

        mpxjBean = projectChangeService.modifyPlan(mpxjBean, proId, pcId);

        if (mpxjBean != null) {
            json.put("mpxjBean", mpxjBean);
        }
        return json.toJSONString();
    }
}
